package com.yc.cloud.common.oss.comparator;

import cn.hutool.core.io.FileUtil;
import lombok.val;

import java.io.File;
import java.util.Comparator;

/**
 * 分块文件排序类
 */
public class ChunkFileComparator implements Comparator<File> {
    @Override
    public int compare(File o1, File o2) {
        //因为名字直接以chunkNumber命名的
        val prefix1 = FileUtil.getPrefix(o1.getName());
        val prefix2 = FileUtil.getPrefix(o2.getName());
        try {
            if (Integer.parseInt(prefix1) < Integer.parseInt(prefix2)) {
                return -1;
            }
            return 1;
        } catch (Exception e) {
            return 0;
        }
    }
}
